'use strict';

const Controller = require('egg').Controller;
const util = require('../utils');

class vedioController extends Controller {
    /*视频主页数据******************************************************************/
    async videoIndex(){
        const { initInterestData } = require('../utils/index');
        /*分类*/
        const category = await this.ctx.service.mainCategory.mainCategory();
        const categoryResult = initInterestData(category);
        /*专辑列表*/
        const page = this.ctx.query.page || 1;
        const parentId = this.ctx.query.parentId||'';
        const categoryId = this.ctx.query.categoryId || parentId || '';
        const orderByField = this.ctx.query.orderByField || 'sort';
        const videoAblum = await this.ctx.service.video.videoAlbum(page,15,categoryId,orderByField,'');
        const videoRecom = await this.ctx.service.video.videoAlbumSimple(page,5,categoryId,orderByField,true);
        var noticeList = await this.ctx.service.bbs.bbsListSimple(1,10,3);
        var memberList = await this.ctx.service.banner.bannerList('vip_area');
        const data = {
            category:categoryResult,
            videoData:videoAblum,
            categoryId:categoryId,
            parentId:parentId,
            videoRecom:videoRecom,
            memberList:memberList,
            noticeList:noticeList,
        };
        await this.ctx.render('page/video/video.html',{data:data});
    }

    /*视频内容页数据***************************************************************/
    async video_content(){
        const id = this.ctx.params.id || '';
        /*视频简介*/
        const videoAlbumDetail = await this.ctx.service.video.videoAlbumDetail(id);
        /*目录*/
        const videoAlbumOutline = await this.ctx.service.video.videoAlbumOutline(id);
        const data={
            videoDetail:videoAlbumDetail,
            videoOutline:videoAlbumOutline,
            content:true,
        };
        await this.ctx.render('page/video/video_content.html',{data:data});
    }
    
    /*视频播放页数据***************************************************************/
    async video_play(){
        const id = this.ctx.params.id || '';
        const videoInfo = await this.ctx.service.video.videoInfo(id);
        let data = videoInfo.videoInfo;
        const videoAlbumOutline = await this.ctx.service.video.videoAlbumOutline(data.albumId);
        data.videoOutline =  videoAlbumOutline;
        await this.ctx.render('page/video/video_play.html',{data:data});
    }

    /*视频播放作业详情***************************************************************/
    async video_play_task(){
        const id = this.ctx.params.id || '';
        let taskInfo = await this.ctx.service.video.taskInfo(id);
        await this.ctx.render('page/video/video_play_task.html',{data:taskInfo});
    }
}

module.exports = vedioController;
